import 'dart:ui';

import 'package:flame/collisions.dart';
import 'package:flame/components.dart';
import 'package:flutter/material.dart';

class DamageText extends PositionComponent {
  final TextStyle _damageTextStyle = const TextStyle(
      fontSize: 14,
      color: Colors.white,
      fontFamily: 'Menlo',
      shadows: [
        Shadow(color: Colors.red, offset: Offset(1, 1), blurRadius: 1),
      ]);

  Future? delay;

  Future<void> addDamage(int damage) async {
    TextComponent damageText =
        TextComponent(textRenderer: TextPaint(style: _damageTextStyle));
    damageText.text = damage.toString();
    damageText.position = Vector2(-30, 0);
    add(damageText);
    delay = Future.delayed(const Duration(seconds: 1)).then((value) {
      print('removeFromParent ${DateTime.now()}');
      damageText.removeFromParent();
    });
  }

  @override
  void onRemove() {}
}
